#ifndef		__ENGINE_CONVERTER_H_INCLUDED__
#define		__ENGINE_CONVERTER_H_INCLUDED__

#include	<cstdint>
#include	<string>
#include	<vector>

/**
 * Parse data from string.
 *
 * \param source Source string to parse.
 * \return Parsed data.
 */
template<typename T>
T Parse(const std::string & source);

/**
 * Convert data into string.
 */
std::string ToString(bool b);
std::string ToString(int8_t n);
std::string ToString(int16_t n);
std::string ToString(int32_t n);
std::string ToString(int64_t n);
std::string ToString(uint8_t n);
std::string ToString(uint16_t n);
std::string ToString(uint32_t n);
std::string ToString(uint64_t n);
std::string ToString(float f);
std::string ToString(double d);
std::string ToString(const std::string & s);
std::string ToString(const char * s);

/**
 * Get lower case string.
 */
std::string ToLower(const std::string & source);

/**
 * Get upper case string.
 */
std::string ToUpper(const std::string & source);

/**
 * Replace all matched substring. Regex expression NOT supported.
 *
 * \param source Source string to be replaced.
 * \param pattern Search pattern.
 * \param replace String replaced with.
 * \return Result string.
 */
std::string Replace(const std::string & source, const std::string & pattern, const std::string & replace);

/**
 * Trim string.
 *
 * \param source Source string to be trimed.
 * \param trim_chars Trimed character list.
 * \return Result string.
 */
std::string TrimStart(const std::string & source, const std::string & trim_chars);
std::string TrimEnd(const std::string & source, const std::string & trim_chars);
std::string Trim(const std::string & source, const std::string & trim_chars);

/**
 * Split string. Regex expression NOT supported.
 *
 * \param str Source string to be splitted.
 * \param delim_chars Delimiters.
 * \param ignore_empty Optional. Should we ignore empty string?
 * \return Substring list.
 */
std::vector<std::string> Split(const std::string & source, const std::string & delim_chars, bool ignore_empty = true);

/**
* \brief cut the str based on char , when n < 0 cut the all , when n > 0 cut second
* \param str Source string to be splitted.
* \param delim_chars Delimiters.
* \param n split number of times
* \note vector don`t include the separator
* \note "=abc=def=hig=" => n=2 => return abc and def
* \note "=abc=def=hig=" => n=3 => return abc and def and hig
* \note "=abc=def=hig=" => n=4 => return abc and def and hig and a null
* \return Substring list.
*/
std::vector<std::string> Split(const std::string& str, const std::string& separator, int n = -1)

/**
 * \brief compare last part of the string.
 * \note  end_string is the end of str
 * \note  HasSuffix("12345","45") => return true
 * \note  HasSuffix("12345", "123") => return false
 * \param str Source string
 * \param end compare source
 * \return true end_string is the end of str
 * \return false is not the end of str
 */
bool HasSuffix(const char* str, const char* end);

#endif//!	__ENGINE_CONVERTER_H_INCLUDED__
